package com.ayu.commentbackend.controller;

import com.ayu.commentbackend.mapper.UserMapper;
import com.ayu.commentbackend.pojo.entity.User;
import com.ayu.commentbackend.pojo.result.Result;
import com.ayu.commentbackend.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    private UserMapper userMapper;

    @PostMapping("/register")
    @ApiOperation("注册")
    public Result register(@RequestBody User user) {
        userService.register(user);
        return Result.success();
    }

    @PostMapping("/login")
    @ApiOperation("登录")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    @PutMapping("/updatePwd")
    @ApiOperation("改密码")
    public Result updatePwd(@RequestBody Map<String,String> params) {
        return userService.updatePwd(params);
    }

    @PostMapping("/update")
    @ApiOperation("改用户信息（不包括密码）")
    public Result update(@RequestBody Map<String, Object> params){
        userService.update(params);
        return Result.success("修改成功");
    }

    @GetMapping("/info")
    @ApiOperation("获取用户信息")
    public Result info(@RequestParam Long id) {
        return Result.success(userService.getUserById(id));
    }
}
